package com.hns.phone.energy.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.master.service.TendencyChartsDataTools;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.phone.energy.vo.CarAnaCarVo;
import com.hns.phone.energy.vo.CarEnergyRankVo;
import com.hns.phone.energy.vo.CarEnergyTendencyVo;
import com.hns.phone.energy.vo.CarEnergyVo;
import com.hns.phone.energy.vo.NewEnergy;
import com.hns.tool.pub.PubUtil;

@Service
public class PhoneCarEnergyService extends CommonService {
	
	@Autowired
    private FillCodeDscValue codeDscValue;
	
	@Autowired
	private TendencyChartsDataTools tendencyChartsDataTools;
	
	/**
	 * 查询故障、线路、排名
	 * @param vo
	 * @return
	 * @throws Exception
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
     @SuppressWarnings("unchecked")
     public List<CarEnergyVo> getCarAnaIdx(CarAnaCarVo vo) throws Exception {
          List<CarEnergyVo>  list =  PubUtil.convertListMapToObject(
              this.sqlMapDao.selectList("phoneCarEnergy.getCarAnaIdx", vo), CarEnergyVo.class);
          return list;
     }
     
     /**
      * 趋势图
      * @param vo
      * @return
      * @throws Exception
      * @author:zhangyu
      * @email:zhangyu2222z@sina.cn
      */
      @SuppressWarnings("unchecked")
      public List<CarEnergyTendencyVo> getCarAnaTrend(CarAnaCarVo vo) throws Exception {
    	  List tmpList = tendencyChartsDataTools.fillSingleTendencyData(this.sqlMapDao.selectList("phoneCarEnergy.getCarAnaTrend", vo), vo.getDateType());
    	  List<CarEnergyTendencyVo>  list =  PubUtil.convertListMapToObject(
    			  tmpList, CarEnergyTendencyVo.class);
          return list;
      }
	
      /**
       * 车辆能耗查询
       * @param vo
       * @return
       * @throws Exception
       * @author:Fisher
       * @email:zhuangcaijin@126.com
       */
      @LeftOrgAnnotation()
      @Transactional
      public Pagination searchCarEnergy(NewEnergy vo) throws Exception {
          Pagination page = this.myBatisPage("phoneCarEnergy.searchCarEnergyCount", "phoneCarEnergy.searchCarEnergy", vo, CarEnergyRankVo.class);
          List<Object> list = page.getData();
          //转化生成线路名称
          Map<String,String> map = new HashMap<String,String>();
          map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
          FillParamsVo fileVo1 = new FillParamsVo("lineId", map);
          //转化生成车牌号、车辆类别、车辆、燃料类型
          map= new HashMap<String,String>();
          map.put("licPltNo",  GlobalConst.DEFAULT_CACHE_VALUE);
          FillParamsVo fileVo3 = new FillParamsVo("carId", map);
          //转化生成驾驶员名称
          map = new HashMap<String,String>();
          map.put("drvName",  GlobalConst.DEFAULT_CACHE_VALUE);
          FillParamsVo fileVo4 = new FillParamsVo("drvId", map);
          codeDscValue.fillInfoValue(list,new String[] {GlobalConst.CACHE_KEY_BASE_LINE_INFO, 
              GlobalConst.CACHE_KEY_BASE_DRV_INFO, GlobalConst.CACHE_KEY_BASE_CAR_INFO}, fileVo1,  fileVo3, fileVo4);
          page.setData(list);
          return page;
      }
      
      /**
       * 车辆能耗查询
       * @param vo
       * @return
       * @throws Exception
       * @author:Fisher
       * @email:zhuangcaijin@126.com
       */
      @SuppressWarnings("unchecked")
	@LeftOrgAnnotation()
      @Transactional
      public List<CarEnergyRankVo> searchSoloCarEnergyRank(NewEnergy vo) throws Exception {
    	  List<CarEnergyRankVo> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("phoneCarEnergy.searchSoloCarEnergyRank", vo), CarEnergyRankVo.class);
    	  int count = (Integer)sqlMapDao.selectOne("phoneCarEnergy.searchCarEnergyCount", vo);
    	  if(PubUtil.isNotEmpty(list)){
    		  for(int i=0;i<list.size();i++){
    			  CarEnergyRankVo entity = (CarEnergyRankVo)list.get(i);
    			  entity.setTotal(count);
    		  }
    	  }
//          Pagination page = this.myBatisPage("phoneCarEnergy.searchCarEnergyCount", "phoneCarEnergy.searchCarEnergy", vo, CarEnergyRankVo.class);
          //转化生成车牌号、车辆类别、车辆、燃料类型
          Map<String,String> map= new HashMap<String,String>();
          map.put("licPltNo",  GlobalConst.DEFAULT_CACHE_VALUE);
          FillParamsVo fileVo3 = new FillParamsVo("carId", map);
          codeDscValue.fillInfoValue(list,new String[] {GlobalConst.CACHE_KEY_BASE_CAR_INFO},   fileVo3);
          return list;
      }

	public List<CarEnergyTendencyVo> getLineAnaTrend(CarAnaCarVo vo) {
		List tempList = tendencyChartsDataTools.fillSingleTendencyData(this.sqlMapDao.selectList("phoneCarEnergy.getLineAnaTrend", vo), vo.getDateType());
		List<CarEnergyTendencyVo>  list =  PubUtil.convertListMapToObject(tempList, CarEnergyTendencyVo.class);
        return list;
	}

	/**
     * 车辆能耗查询（前五）
     * @param vo
     * @param response
     * @param request
     * @throws Exception
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     */
	public List<CarEnergyRankVo> searchCarEnergyForFive(NewEnergy vo) {
		List<CarEnergyRankVo> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("phoneCarEnergy.searchCarEnergyForFive", vo), CarEnergyRankVo.class);
		return list;
	}
      
}
